package com.carefree.system.modules.security.exception;

import com.carefree.common.core.Result;
import com.carefree.common.emus.StatusCodeEnum;
import com.carefree.system.common.utils.WebUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName:AuthenticationEntryPointHandler
 * @Description: 步骤五: 1.认证失败处理
 * @Author Tengbin tengbin234@163.com
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {


    /**
     * @param request       that resulted in an <code>AuthenticationException</code>
     * @param response      so that the user agent can begin authentication
     * @param authException that caused the invocation
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        WebUtils.renderString(response, Result.error(StatusCodeEnum.ACCOUT_PASSWORD_ERROR.getMessage()));
    }
}
